package com.ivan.toolkit.common;

import lombok.Getter;
import lombok.Setter;

public class WatchDog {
	
	@Getter
	private long lastFeed = 0;
	
	@Getter @Setter
	private long livemillis = 0;

	public WatchDog(long lastFeed, long liveMillis) {
		this.lastFeed = lastFeed;
		this.livemillis = liveMillis;
	}
	
	public WatchDog(long liveMillis) {
		this(System.currentTimeMillis(), liveMillis);
	}
	
	public void feed() {
		this.lastFeed = System.currentTimeMillis();
	}
	
	public void keepAlive() {
		this.lastFeed = System.currentTimeMillis();
	}
	
	public boolean isAlive(long expired) {
		return (System.currentTimeMillis() - lastFeed) < expired;
	}
	
	public boolean isAlive() {
		return (System.currentTimeMillis() - lastFeed) < livemillis;
	}

	
}
